// 回合结算模块
class roundEndGameObj extends eui.Component {
    private score_Txt: eui.BitmapLabel;
    //private alphaBg:eui.Image;
    private handPokerBg: egret.Sprite;
    private winPokerBg: egret.Sprite;
    private image: playImage2;
    private luckyMc: lucky;

    public constructor() {
        super();
        this.once(eui.UIEvent.COMPLETE, this.onComplete, this);
        this.skinName = "src/Game/gameRoom/end/roundEndGameObjSkin.exml";
    }
    private onComplete() {
        this.image = new playImage2();
        this.image.scaleX = this.image.scaleY = 0.7;
        this.image.y = 18;
        this.image.x = 18;
        this.addChild(this.image);

        this.winPokerBg = new egret.Sprite();
        this.addChild(this.winPokerBg);
        this.handPokerBg = new egret.Sprite();
        this.addChild(this.handPokerBg);
        this.updatexy();
    }
    private updatexy() {
        this.winPokerBg.x = 90;//this.image.x + this.image.width + 10;
        this.winPokerBg.y = 20;//(this.height - this.winPokerBg.height)/2;
        if (this.winPokerBg.numChildren) {
            this.handPokerBg.x = this.winPokerBg.x + this.winPokerBg.width + 4;
        } else {
            this.handPokerBg.x = this.winPokerBg.x + this.winPokerBg.width;
        }
        this.handPokerBg.y = 30;//(this.height - this.handPokerBg.height)/2;
    }
    public setContent(imageUrl: string, userName: string, handPoker: any, winPoker: any, huPoker: any, zhaMaList: any, winScore: number, bankerIndex: number, seatIndex: number, zhaMaConut: number, suitPatterns: any, showText: any, winCards: any) {
        // const {hu, dianpao, headUrl, nickname, handList, winPoker, huPoker, winScore, seatIndex, zhaMaConut, suitPatterns, showText} = lsData
        // console.log('lsData', lsData);
        // var handPoker = handList
        // var actionList = winPoker
        // var winCard = huPoker
        // var point = winScore
        // var zhaMa = zhaMaConut


        // var isDianpao = hu === true && dianpao === 1 
        // var isFangpao = hu === true && dianpao === 1 
        
        this.visible = false;
        this.image.setContent(imageUrl, userName);
        this.image.setOwner(false);
        this.image.setOffLine(false);
        if (bankerIndex == seatIndex) {
            this.image.setBanker(true);
        } else {
            this.image.setBanker(false);
        }

        console.log(winPoker, handPoker);
        console.log('showText', showText);
        for (var i = 0; i < winPoker.length; i++) {
            if (!winPoker[i].actionCard || winPoker[i].actionCode === 3) {
                continue
            }
            let lsobj: winPENG = new winPENG();
            lsobj.scaleX = lsobj.scaleY = 0.7;
            lsobj.setContent(winPoker[i].actionCard.suitType + "_" + winPoker[i].actionCard.count + "_png", GameData.winPokerCode[winPoker[i].actionCode]);
            lsobj.x = this.winPokerBg.numChildren * +((110) + 4);
            this.winPokerBg.addChild(lsobj);
            this.winPokerBg.width = this.winPokerBg.numChildren * ((110) + 4);
        }

        for (var n = 0; n < handPoker.length; n++) {
            var pmc: endHandPoker = new endHandPoker();
            pmc.scaleX = pmc.scaleY = 0.45;
            pmc.setContent(handPoker[n].suitType + "_" + handPoker[n].count + "_png");
            this.handPokerBg.addChild(pmc);
            pmc.x = 37 * n;//35*n;                     
        }
        this.handPokerBg.width = 37 * handPoker.length;
        //let timer = egret.setTimeout(()=>{
        //   egret.clearTimeout(timer);
        this.updatexy();
        if (showText) {
            var textLabel = new eui.Label(showText)
            textLabel.x = 540
            textLabel.y = -15
            this.winPokerBg.addChild(textLabel)
        }
        let scoreStr: string;
        if (winScore >= 0) {
            this.score_Txt.font = "font_point-Jia_fnt";
            scoreStr = "+" + winScore;
        } else {
            this.score_Txt.font = "font_point-jian_fnt";
            scoreStr = String(winScore);
        }
        this.score_Txt.text = scoreStr;
        this.score_Txt.x = this.width - (scoreStr.length * 33) - 30;

        // let huMc: endHandPoker;
        if (winCards && winCards.length) {
            winCards.forEach((hulepai, huleIndex) => {
                if (!hulepai) {
                    return
                }
                const huMc = new endHandPoker();
                huMc.setContent(hulepai.suitType + "_" + hulepai.count + "_png");
                huMc.scaleX = huMc.scaleY = 0.45;
                huMc.y = 30;
                huMc.x = this.handPokerBg.x + this.handPokerBg.width + 10 + huleIndex * huMc.width * 0.45;
                this.addChild(huMc);
            })
        }
        if (zhaMaList && zhaMaList.length > 0) {
            if (this.luckyMc) {
                this.removeChild(this.luckyMc);
                this.luckyMc = null;
            }
            this.luckyMc = new lucky();
            console.log('zhaMaList', zhaMaList);
            this.luckyMc.setContent(zhaMaList, zhaMaList.length);
            this.addChild(this.luckyMc);
            this.luckyMc.anchorOffsetX = this.luckyMc.width / 2;
            // const huXXX = this.handPokerBg.x + this.handPokerBg.width + 10;
            // let lsWidth: number = this.width - (huXXX + 45 + (this.width - this.score_Txt.x));
            this.luckyMc.x = 750
            this.luckyMc.y = 4;
        }
        this.visible = true;
        //扎码
        if (seatIndex == GameData.mySeatIndex) {
            this.isclor(true);
        }
        console.log('suitPatterns', suitPatterns);
        if (suitPatterns) {
            const patternArr = []
            suitPatterns.forEach(pattern => {
                var imgName = ''
                switch (pattern) {
                    case 2:
                        imgName = ''
                        break
                    case 3:
                        imgName = 'qiangganghu-label_png'
                        break
                    case 4:
                        imgName = 'gangshagnkaihua-label_png'
                        break
                    case 9:
                        imgName = 'banbanhu-label_png'
                        break
                    case 12:
                        imgName = 'qingyise-label_png'
                        break
                    case 13:
                        imgName = 'pengpenghu-label_png'
                        break
                    case 14:
                        imgName = 'jiangjianghu-label_png'
                        break
                    case 15:
                        imgName = 'haidilao-label_png'
                        break
                    case 16:
                        imgName = 'haidipao-label_png'
                        break
                    case 17:
                        imgName = 'xiaoqidui-label_png'
                        break
                    case 18:
                        imgName = 'haohuaqidui-label_png'
                        break
                    case 20:
                        imgName = 'gangshagnpao-label_png'
                        break
                    case 21:
                        imgName = 'shuanghaoqidui-label_png'
                        break
                    case 22:
                        imgName = 'chaohaoqidui-label_png'
                        break
                }
                if (imgName !== '') {
                    patternArr.push(imgName)
                }
            })
            patternArr.forEach((imgSrc, index) => {
                var imgEle = MyLibrary.createBitmapByName(imgSrc)
                imgEle.x = 80 + index * 240
                imgEle.y = this.height - 30
                imgEle.scaleX = imgEle.scaleY = .5
                this.addChild(imgEle)
            })
            console.log('patternArr', patternArr);
        }
        //},this,200);
    }
    //设置高亮显示
    public isclor(value: boolean) {
        /*if(value){
            this.alphaBg.alpha = 0.5;
        }else{
            this.alphaBg.alpha = 0;
        }*/
    }
}